package com.youth.youthservice.service.impl;

import java.io.*;
import java.util.Base64;

/**
 * @ClassName demo
 * @Description TODO
 * @date 2023/11/9 21:08
 * @Version 1.0
 */
public class demo {

    public static void main(String[] args) throws UnsupportedEncodingException {

        String img = "C:\\Users\\15878\\Pictures\\Screenshots\\ys.png";

        File file = new File(img);

        // 使用tryResource
        try (FileInputStream fis = new FileInputStream(file)) {
            byte[] bytes = new byte[(int) file.length()];
            fis.read(bytes);  //将字节数组转储到bytes中
            System.out.println(Base64.getEncoder().encodeToString(bytes));
            // System.out.println(Base64.getEncoder().encodeToString(img.getBytes()));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
